<?php
$user = $data['user'];
//dump($data);
?>
<!DOCTYPE html>
<html lang="zhcn">
<head>
    <include file="Common/meta" />
    <title>修改密码 - {$_ENV['site'][0]['title']}</title>
    <include file="Common/link" />
</head>
<body>
<header class="layout-header">
    <div class="container">
        <h1 class="title">修改密码</h1>
        <a class="header-back" href="/user/updatePage"><i class="icon icon-left"></i></a>
    </div>
</header>
<div class="layout-body">
    <div class="container">
        <section class="change-psw">
            <label class="change-psw-label">输入旧密码</label>
            <div>
                <input id="oldPwd" class="change-psw-input" type="password">
            </div>
            <label>输入新密码</label>
            <div>
                <input id="newPwd" class="change-psw-input" type="password">
            </div>
            <label>确认新密码</label>
            <div>
                <input id="repeatPwd"  class="change-psw-input" type="password">
            </div>
            <label></label>
            <div>
                <input id="save" class="change-psw-submit" value="确定" type="button">
            </div>
        </section>
    </div>
</div>
<include file="Common/script" />
<script>
    // 修改密码
    $('#save').on('click', function (e) {
        e.preventDefault();

        var oldPwd = $('#oldPwd').val();
        if (!oldPwd) {
            eui.msg('请输入原密码');
            return;
        }

        var newPwd = $('#newPwd').val();
        if (!newPwd) {
            eui.msg('请输入新密码');
            return;
        }

        var repeatPwd = $('#repeatPwd').val();
        if (!repeatPwd) {
            eui.msg('请输入重复密码');
            return;
        }

        if (newPwd != repeatPwd) {
            eui.msg('两次密码输入不一致');
            return;
        }

        $.ajax({
            url: '/user/changePswd',
            data: {
                password: newPwd
            },
            type: 'post',
            dataType: 'json',
            success: function (obj) {
                if (obj.code === 0) {
                    eui.msg('修改成功');
                } else {
                    eui.msg('修改失败，' + obj.msg);
                }
            },
            error: function () {
                eui.alert('系统出错');
            }
        });

    });
</script>
</body>
</html>